<style lang="less">
@import './login.less';
</style>

<template>
  <div class="login">
    <div class="login-con">
      <Card icon="log-in" :title="$t('3HI9TUTup77fchsuJtxJo')" :bordered="false">
        <div class="form-con">
          <login-form @on-success-valid="handleSubmit"></login-form>
          <!-- <p class="login-tip">输入任意用户名和密码即可</p> -->
        </div>
      </Card>
    </div>
  </div>
</template>

<script>
import LoginForm from '_c/login-form'
import { mapActions } from 'vuex'
import iView from 'iview'
export default {
  components: {
    LoginForm
  },
  methods: {
    ...mapActions(['handleLogin', 'getUserInfo']),
    handleSubmit ({ userName, password }) {
      iView.LoadingBar.start()
      this.handleLogin({ userName, password }).then(
        res => {
          if (res.code == 200) {
            this.getUserInfo().then(res => {
              // this.$router.push({
              //   name: this.$config.homeName
              // })
              if (res.operatorId == 0 && res.stationId == 0) { // admin
                this.$router.push({ name: 'agent_info' })
              } else if (res.operatorId != 0 && res.stationId == 0) { // 运营商
                this.$router.push({ name: 'user_edit' })
              } else if (res.operatorId != 0 && res.stationId != 0) { // 充电站
                this.$router.push({ name: 'station_manage' })
              }
            })
          } else {
            this.$Message.error(res.desc)
          }
        },
        err => {
          this.$Message.error(err)
        }
      ).finally(() => {
        iView.LoadingBar.finish()
      })
    }
  }
}
</script>

<style></style>
